package com.topfinance.payment.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;

import com.topfinance.cnaps2.ebo.ConfOutPortEbo;
import com.topfinance.frame.dao.HibernateEntityDao;
import com.topfinance.frame.exception.AppException;
import com.topfinance.payment.dto.TCfgInPortDto;
import com.topfinance.payment.ebo.TCfgFormatEbo;
import com.topfinance.payment.ebo.TCfgNodeEbo;
import com.topfinance.payment.ebo.TCfgPortInEbo;
import com.topfinance.payment.ebo.TCfgPortOutEbo;
import com.topfinance.payment.ebo.TCfgProtocolEbo;
import com.topfinance.payment.ebo.TCfgTransInEbo;
import com.topfinance.payment.service.ITCfgPortInMgr;

/**
 * 该类自动实现了dao的一般方法，如add, remove, update
 * 在service中出现的大部分情况下是在向后台提交数据前的处理(如校验)及获取后台数据后的处理等
 * @author
 *
 */

public class TCfgPortInMgrImpl extends HibernateEntityDao<TCfgPortInEbo> implements ITCfgPortInMgr {

	private static final Log log = LogFactory.getLog(TCfgPortInMgrImpl.class);
	
	//获得传输协议	
	public TCfgPortInEbo getTCfgPortIn(Integer oid) throws AppException{
		return (TCfgPortInEbo)get(oid);
	}

	public void deleteTCfgPortIn(Integer oid) throws AppException{
		removeById(TCfgPortInEbo.class,oid);
	}

	//获得传输协议列表
	public List<TCfgPortInEbo> getAllPortIn() throws AppException{
		String hql = " from TCfgPortInEbo t " ;
		String where = "";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where;
		}
		hql = hql + where;
		return find(hql,paramList.toArray());		
	}

	public TCfgPortInEbo getInPort(Integer oid) throws AppException {
		// TODO Auto-generated method stub
		return (TCfgPortInEbo)get(oid);
	}

	public TCfgPortInEbo addInPort(TCfgInPortDto pt) throws AppException {
		// TODO Auto-generated method stub
		TCfgTransInEbo to = (TCfgTransInEbo)get(TCfgTransInEbo.class,pt.getTID());
		TCfgProtocolEbo po = (TCfgProtocolEbo)get(TCfgProtocolEbo.class,pt.getPID());
		TCfgNodeEbo no = (TCfgNodeEbo)get(TCfgNodeEbo.class,pt.getNID());
		TCfgPortOutEbo opo = (TCfgPortOutEbo)get(TCfgPortOutEbo.class,pt.getAckpID());
		TCfgFormatEbo fo = (TCfgFormatEbo)get(TCfgFormatEbo.class,pt.getFID());
		TCfgPortInEbo p = new TCfgPortInEbo();
		BeanUtils.copyProperties(pt, p);
		p.setTCfgNode(no);
		p.setTCfgTransIn(to);
		p.setTCfgProtocol(po);
		p.setTCfgPortOut(opo);
		p.setTCfgFormat(fo);
		save(p);
		return p;
	}

	public void deleteInPort(TCfgInPortDto o) throws AppException {
		// TODO Auto-generated method stub
		removeById(TCfgPortInEbo.class,o.getOid());
	}

	public void deleteInPort(Integer id) throws AppException {
		// TODO Auto-generated method stub
		removeById(TCfgPortInEbo.class,id);
	}

	public void editInPort(TCfgInPortDto pt) throws AppException {
		// TODO Auto-generated method stub
		TCfgTransInEbo to = (TCfgTransInEbo)get(TCfgTransInEbo.class,pt.getTID());
		TCfgProtocolEbo po = (TCfgProtocolEbo)get(TCfgProtocolEbo.class,pt.getPID());
		TCfgNodeEbo no = (TCfgNodeEbo)get(TCfgNodeEbo.class,pt.getNID());
		TCfgPortOutEbo opo = (TCfgPortOutEbo)get(TCfgPortOutEbo.class,pt.getAckpID());
		TCfgFormatEbo fo = (TCfgFormatEbo)get(TCfgFormatEbo.class,pt.getFID());
		TCfgPortInEbo p = (TCfgPortInEbo)get(TCfgPortInEbo.class,pt.getOid());
		BeanUtils.copyProperties(pt, p);
		p.setTCfgNode(no);
		p.setTCfgTransIn(to);
		p.setTCfgProtocol(po);
		p.setTCfgPortOut(opo);
		p.setTCfgFormat(fo);
		update(p);
	}

}
